import { FastifyInstance } from "fastify";
import { MetroStation, City } from "@db";

export const metro = async (fastify: FastifyInstance) => {
    fastify.get("/metro", async (req, res) => {
        const cities = (
            await City.findAll({
                include: { model: MetroStation },
            })
        )
            .map((city) => {
                return [
                    ...city.MetroStations.map(({ id, name, line }) => {
                        return {
                            id,
                            name,
                            line,
                            city: {
                                id: city.id,
                                name: city.name,
                            },
                        };
                    }),
                ];
            })
            .flat();
        return res.send(cities);
    });
};
